$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'qyxxddddywnew/list',
        datatype: "json",
        colModel: [
            { label: 'id', name: 'id', index: "id", width: 45, key: true,hidden:true },
            { label: '查看详情', name: 'ddxq', index: 'XQ', width: 80,
                formatter:function (cellvale, options, rowObject){
                    return "<a class='btn btn-modify'  onclick='vm.detail(\"" + rowObject.id + "\", \"" + rowObject.deptId + "\")' style='display: inline;'>详情</a>";
                }
            },
			{ label: '登记序号', name: 'ddywDjxh', index: 'DDYW_DJXH', width: 80 }, 
			{ label: '企业名称', name: 'ddywQymc', index: 'DDYW_QYMC', width: 80 }, 
			{ label: '企业代码', name: 'ddywQydm', index: 'DDYW_QYDM', width: 80 }, 
			{ label: '当品号', name: 'ddywDph', index: 'DDYW_DPH', width: 80 }, 
			{ label: '业务类型代码', name: 'ddywYwlxCode', index: 'DDYW_YWLX_CODE', width: 80 }, 
			{ label: '业务类型', name: 'ddywYwlxName', index: 'DDYW_YWLX_NAME', width: 80 }, 
			{ label: '经办人', name: 'ddywTbr', index: 'DDYW_TBR', width: 80 },
			{ label: '登记日期', name: 'createDate', index: 'createDate', width: 80 }
        ],
		viewrecords: true,
        height: 365,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
        q:{

        },
        showList: true,
        showDetail: false,
		title: null,
		qyxxDdDdywNew: {},
        ddywYwlxName:[{text:'类型一',value:'类型一'},{text:'类型二',value:'类型二'}],
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.qyxxDdDdywNew = {};
		},
		update: function (event) {
            var id = getSelectedRow();
            if(id == null){
                return ;
            }
			vm.showList = false;
            vm.title = "修改";
            vm.getInfo(id)
		},
		saveOrUpdate: function (event) {
			var url = vm.qyxxDdDdywNew.id == null ? "qyxxddddywnew/save" : "qyxxddddywnew/update";
            // if ( vm.qyxxDdDdywNew.ddywDjxh == "" ) {
            //     alert("企业登记序号不能为空！");
            //     return;
            // }
            vm.qyxxDdDdywNew.upload = $("#furl1").val();
            $.ajax({
				type: "POST",
			    url: baseURL + url,
			    contentType: "application/json",
			    data: JSON.stringify(vm.qyxxDdDdywNew),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: baseURL + "qyxxddddywnew/delete",
				    contentType: "application/json",
				    data: JSON.stringify(ids),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(id){
			$.get(baseURL + "qyxxddddywnew/info/"+id, function(r){
                vm.qyxxDdDdywNew = r.qyxxDdDdywNew;
            });
		},
        detail: function (id) {
            vm.showDetail = true;
            vm.getInfo(id);
        },

		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page,
                postData:{'name':vm.q.name}
            }).trigger("reloadGrid");
		}
	}
});
function fileupload(thisid){

        var fd=new FormData();
        fd.append('file',$("#file").get(0).files[0]);
        $.ajax({
            type: "post",
            dataType: "json",
            async: false,
            cache: false,
            url: '/fileTransfer/upload',
            processData: false,  // 告诉jQuery不要去处理发送的数据
            contentType: false,   // 告诉jQuery不要去设置Content-Type请求头
            data: fd,
            //}).then(function (result) {
            success: function (result) {
                if (result.code == 0) {
                    var qq=JSON.stringify(result);
                     console.log(result.path[0]);
                	$("#furl1").val(result.path[0]);
                	$(".upimg").html("<img src='"+result.path[0]+"'/>");
                }
            },

        });

}